<template>
  <div class="app-container">
    <div class="head_search u-f u-f-ac u-fw" v-if="daili">
      <div class="ipt_box u-f u-f-ac u-f-jsb">
        <p class="label font14 text_black">{{$t('用户名')}}：</p>
        <el-input v-model="agent" :placeholder="$t('请输入代理商名字')"></el-input>
      </div>
      <div class="ipt_box u-f u-f-ac u-f-jsb">
        <p class="label font14 text_black">{{$t('手机号')}}：</p>
        <el-input v-model="phone" :placeholder="$t('请输入代理手机号')"></el-input>
      </div>
      <div class="select_box u-f u-f-ac u-f-jsb">
        <p class="label font14 text_black">{{$t('身份')}}：</p>
        <el-select
          v-model="clientVal"
          :placeholder="$t('请选择')"
          @change="clientChange"
        >
          <el-option
            v-for="item in clientArr"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <button class="sub_btn font14 text_white bg_blue" @click="getData('search')">
        {{$t('提交')}}
      </button>
    </div>

    <div>
      <el-table :data="tableData">
        <el-table-column
          prop="name"
          :label="$t('用户名')"
        ></el-table-column>
        <el-table-column
          prop="phone"
          :label="$t('手机号')"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="user_type"
          :label="$t('身份')"
        >
          <template slot-scope="{row}">
            <span v-if="row.user_type == 1">{{$t('代理商')}}</span>
            <span v-if="row.user_type == 2">{{$t('业务员')}}</span>
            <span v-if="row.user_type == 3">{{$t('商户管理')}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="total_amount" :label="$t('总金额')"></el-table-column>
        <el-table-column
          prop="balance"
          :label="$t('账户余额')"
        ></el-table-column>
        <el-table-column
          prop="audit_amount"
          :label="$t('待审核金额')"
        >
        <template slot-scope="{row}">
            <span>{{cutOutNums(row.audit_amount+row.audit_amounta)}}</span>
          </template>
      </el-table-column>
        <el-table-column
          prop="freeze_amount"
          :label="$t('冻结金额')"
        ></el-table-column>
        <el-table-column
          prop="withdrawal_amount"
          :label="$t('累计提现金额')"
        ></el-table-column>
      </el-table>

      <div class="pagination_box ">
        <el-pagination
          background
          
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-size="page_size"
          layout="total, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <refresh @click="handleRefresh"></refresh>

  </div>
</template>

<script>
import util from '@/assets/js/util.js'
import { mapState } from "vuex";
export default {
  name: 'finance-agency',
  data() {
    let that = this
    return {
      daili: true,
      page: 1,
      page_size: 20,
      total: 0,
      agent: "",
      phone: '',
      clientVal: 0,
      clientArr: [
        {
          value: 0,
          label: that.$t('选择身份')
        },
        {
          value: 1,
          label: that.$t('代理商')
        },
        {
          value: 2,
          label: that.$t('业务员')
        },
        {
          value: 3,
          label: that.$t('商户管理')
        },
      ],
      tableData: [],
    };
  },
  mounted() {
    //判断一下
    if(this.memusid==5){
      this.daili = false;
      this.agencyDialogAll();
      
      return false;
    }
    this.getData()
  },
  computed: {
    ...mapState(["permissions","memusid","uid","name"])
  },
  methods: {
    cutOutNums(num) {
      return parseFloat(num).toFixed(2);
    },
    handleRefresh() {
      this.page = 1
      this.page_size = 20
      this.agent = ''
      this.phone = ''
      this.clientVal = 0
      this.getData()
    },
    agencyDialogAll(type) {
      if(type == 'search') { this.page = 1 }
      util.$http('/agency/agencyDialog2?page=' + this.page, {
        page_size: this.page_size,
        name: this.agent,
        phone: this.phone,
        type: this.clientVal,
        uid: this.uid
      })
      .then(res=>{
        if(res.code == 1) {
          this.total = res.data.total
          this.tableData = res.data.list
        }
      })
    },
    getData(type) {
      if(type == 'search') { this.page = 1 }
      util.$http('/finance/agency?page=' + this.page, {
        page_size: this.page_size,
        name: this.agent,
        phone: this.phone,
        type: this.clientVal,
      })
      .then(res=>{
        if(res.code == 1) {
          this.total = res.data.total
          this.tableData = res.data.list
        }
      })
    },
    clientChange(val) {
      this.clientVal = val;
    },
    handleCurrentChange(val) {
      this.page = Number(val)
      this.getData()
    },
  }
};
</script>

<style scoped>
.head_search {
  margin-bottom: 20px;
}
.head_search .ipt_box {
  width: 260px;
  margin-right: 20px;
}
.head_search .ipt_box .el-input {
  width: 200px;
}
.head_search .select_box {
  width: 280px;
  margin-right: 20px;
}
.head_search .select_box .el-select {
  width: 200px;
}
.head_search .switch_box {
  width: 151px;
  margin-right: 20px;
}
.head_search .sub_btn {
  width: 70px;
  height: 40px;
  border: 0;
  outline: 0;
  cursor: pointer;
  border-radius: 4px;
}
.head_tip {
  margin: 0 0 10px 0;
  padding-bottom: 5px;
  border-bottom: 1px solid #ebeef5;
}
.iconfont {
  font-size: 15px;
  margin-right: 5px;
}
.el-button--mini,
.el-button--mini.is-round {
  padding: 7px 10px;
}
.pagination_box {
  padding-top: 30px;
}
.pagination_box .el-pagination {
  display: flex;
  justify-content: flex-end;
}
.avatar{
  width: 40px;
  height: 40px;
}
</style>
